<?php
// 只能在当前 request 生命周期缓存，要跨进程，可以再加一层缓存： memcached/xcache/apc/
$g_static_users = array(); // 变量缓存

// hook model_user_start.php

// ------------> 最原生的 CURD，无关联其他数据。

function verified__create($arr) {
	// hook model_verified__create_start.php
	$r = db_insert('verified', $arr);
	// hook model_verified__create_end.php
	return $r;
}

function verified__update($vid, $update) {
	// hook model_verified__update_start.php
	$r = db_update('verified', array('vid' => $vid), $update);
	// hook model_verified__update_end.php
	return $r;
}

function verified__read($vid) {
	// hook model_verified__read_start.php
	$verified = db_find_one('verified', array('vid' => $vid));
	// hook model_verified__read_end.php
	return $verified;
}

function verified__delete($vid) {
	// hook model_verified__delete_start.php
	$r = db_delete('verified', array('vid' => $vid));
	// hook model_verified__delete_end.php
	return $r;
}

function verified__find($cond = array(), $orderby = array(), $page = 1, $pagesize = 1000) {
	// hook model_verified__find_start.php
	$verifiedlist = db_find('verified', $cond, $orderby, $page, $pagesize, 'vid');
	// hook model_verified__find_end.php
	return $verifiedlist;
}
// ------------> 关联 CURD，主要是强相关的数据，比如缓存。弱相关的大量数据需要另外处理。

// 新建实名制
function verified_create($uid, $name, $number, $cpurl, $cnurl, $bcurl) {
	$r = verified__create(array(
		'uid' => $uid,
		'name' => $name,
		'number' => $number,
		'cpurl' => $cpurl,
		'cnurl' => $cnurl,
		'bcurl' => $bcurl,
	));
	return $r;
}

// 更新实名制
function verified_update($vid, $update) {
	$r = verified__update($vid, $update);

	return $r;
}

// 查看单个实名制
function verified_read($vid) {
	$verified = verified__read($vid);
	return $verified;
}

// 查看所有实名制
function verified_read_all($review = 0) {
	$cond = array();
	$cond['review'] = $review;
	$verifiedlist = verified__find($cond);
	return $verifiedlist;
}

function verified_read_uid($uid) {
	$cond = array();
	$cond['uid'] = $uid;
	$verified = db_find_one('verified', $cond);
	return $verified;
}

// 判断用户已经提交实名制
function verified_if_uid($uid) {
	$verified = verified_read_uid($uid);
	if (empty($verified)) {
		//没有提交审核
		return -2;
	} else {
		if ($verified['review'] == 0) {
			//等待审核
			return 0;
		} elseif ($verified['review'] == 1) {
			return 1;
		} elseif ($verified['review'] == -1) {
			return -1;
		}
	}
	return -3;
}

// 通过实名
function verified_review($vid, $review) {
	$update = array();
	$update['review'] = $review;
	$r = verified_update($vid, $update);
	return $r;
}

function verified_maxid() {
	// hook model_verified_maxid_start.php
	$n = db_maxid('verified', 'vid');
	// hook model_verified_maxid_end.php
	return $n;
}

?>